class Frontend::MicopostsController < Frontend::BaseController

  before_action :set_micopost, only: [:show, :edit, :delete, :update]

  def index
    @micoposts = Micopost.all.sorted.page(params[:page])
  end

  def new

  end


  def show

  end

  # 发布post
  def create
    @micopost = Micopost.new(micopost_params)
    if @micopost.post_by_user(current_user)
      redirect_to frontend_root_path, notice: '发布成功'
    else
      flash[:alert] = "发布失败"
      redirect_to frontend_root_path
    end
  end

  def edit

  end

  def update

  end

  def delete

  end


  private

  def set_micopost
    @micopost = Micopost.find(params[:id])
  end


  def micopost_params
    params.require(:micopost).permit!
  end

end
